﻿namespace Sidvall.Web.IO.Data
{
    public class ResourceActionResultCollection : System.Collections.ObjectModel.KeyedCollection<string, ResourceActionResult>
    {
        #region Public Members

        #region Add

        public void Add(string action, Sidvall.Security.ResourceItem resourceItem)
        {
            var item = new ResourceActionResult()
            {
                Action = action,
                ResourceItem = resourceItem,
            };
            Add(item);
        }

        #endregion
        #region FindItem

        public ResourceActionResult FindItem(string action)
        {
            if (string.IsNullOrWhiteSpace(action))
                return null;
            if (Contains(action))
                return this[action];
            return null;
        }

        #endregion
        #region GetKeyForItem

        protected override string GetKeyForItem(ResourceActionResult item)
        {
            if (item == null)
                throw new System.ArgumentNullException(nameof(item));
            return item.Action;
        }

        #endregion

        #endregion
    }
}
